﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using SMS.DAL;
using SMS.DAL.Providers;

namespace SMS.Business
{
    public class OrderItemsBussiness : BusinessBase<OrderItem,OrderItemSearchCriteria>
    {
        public override bool Insert(OrderItem item)
        {
            OrderItemProvider orderItemProvider = new OrderItemProvider();
            StockItem stockItem = item.StockItem;
            StockItemsProvider stockItemProvider = new StockItemsProvider();
            //ItemProvider itemProv = new ItemProvider();

            if (item.Order.Type == 1)       // if buying Order
            {
                stockItem.Count += item.ItemCount;
            }
            else
            {
                if (item.Order.Type == 2)    // if Selling order
                {
                    stockItem.Count -= item.ItemCount;
                }
            }

            stockItemProvider.Update(stockItem);
            orderItemProvider.Insert(item);
            return true;
        }

        public override bool Update(OrderItem updatedItem)
        {
            throw new NotImplementedException();
        }

        public override bool Delete(int id)
        {
            throw new NotImplementedException();
        }

        public override OrderItem GetByID(int id)
        {
            throw new NotImplementedException();
        }

        public override List<OrderItem> Search(OrderItemSearchCriteria SearchCriteria)
        {
            throw new NotImplementedException();
        }

        public void DeleteByOrderID(int id)
        {
            OrderItemProvider orderItemPro = new OrderItemProvider();
            orderItemPro.DeleteByOrderID(id);
        }
    }
}
